// https://acm.hdu.edu.cn/showproblem.php?pid=1276

#include <iostream>
#include <list>
using namespace std;

void train(int m) {
    list<int> L;
    for (int i = 1; i <= m; i++) {
        L.push_back(i);
    }

    bool flag = true;
    while (L.size() > 3) {
        int cnt = 1;
        const int k = flag ? 2 : 3;
        for (list<int>::iterator it = L.begin(); it != L.end(); cnt++) {
            if (cnt % k == 0) {
                it = L.erase(it);
            } else {
                ++it;
            }
        }
        flag = !flag;
    }

    list<int>::iterator iter = begin(L);
    while (iter != end(L)) {
        printf("%d", *iter);
        ++iter;
        if (iter != end(L)) {
            printf(" ");
        }
    }
    printf("\n");
}


int main() {
    int n, m;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &m);
        train(m);
    }
    return 0;
}